package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.AdminDao;
import com.yc.jpyy.mobile.service.AdminService;

@Controller
@RequestMapping(value = "/admin")
public class AdminCountChartController extends BaseController {
	
	@Autowired
	private AdminService adminService;

	@Autowired
	private AdminDao adminDao;
	private static Logger logger = LoggerFactory.getLogger(AdminCountChartController.class);
	
	/**
	 * 首页统计图所有
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getChartDatas", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getChartDatas(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 驾校Id
			String driverId = request.getParameter("driverId");
			if(driverId != null && !driverId.isEmpty()){
				//获取统计图数据
				response = adminService.getChartDatas(driverId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getChartDatas:"+ e.toString());
			response.setReturnMsg(0,"获取统计图数据失败！");
		} finally {
			return response.toJSON();
		}
	}

	/**
	 * 在校学员培训阶段分部
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getStudentTrainStage", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getStudentTrainStage(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 驾校Id
			String driverId = request.getParameter("driverId");
			if(driverId != null && !driverId.isEmpty()){
				//获取统计图数据
				response = adminService.getStudentTrainStage(driverId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getChartDatas:"+ e.toString());
			response.setReturnMsg(0,"获取统计图数据失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 * 学员培训周期分部
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getStudentTrainCycle", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getStudentTrainCycle(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 驾校Id
			String driverId = request.getParameter("driverId");
			if(driverId != null && !driverId.isEmpty()){
				//获取统计图数据
				response = adminService.getStudentTrainCycle(driverId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getChartDatas:"+ e.toString());
			response.setReturnMsg(0,"获取统计图数据失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 * 长期怠学统计分布
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getLongslackStudente", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getLongslackStudente(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {
			// 驾校Id
			String driverId = request.getParameter("driverId");
			if(driverId != null && !driverId.isEmpty()){
				//获取统计图数据
				response = adminService.getLongslackStudente(driverId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getChartDatas:"+ e.toString());
			response.setReturnMsg(0,"获取统计图数据失败！");
		} finally {
			return response.toJSON();
		}
	}
	

}
